import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    CreateDateColumn,
    ManyToOne,
    JoinColumn,
    OneToOne,
    OneToMany,
} from 'typeorm';
import { Article } from './article.entity'
import { User } from './user.entity'


@Entity()
export class ArticleMoment {
    @PrimaryGeneratedColumn('uuid')
    id: string;

    @Column()
    moment: string;

    @Column()
    status: number


    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: true })
    createdAt: Date;

    @CreateDateColumn({ type: 'timestamp', default: () => 'CURRENT_TIMESTAMP(6)', select: false })
    updatedAt: Date;


    @ManyToOne(() => ArticleMoment, articleMoment => articleMoment.children, { nullable: true })
    @JoinColumn({ name: 'parent_id' })
    parentMoment: ArticleMoment | null

    @OneToMany(() => ArticleMoment, articleMoment => articleMoment.parentMoment, { nullable: true })
    children?: ArticleMoment[] | null

    @ManyToOne(() => Article, article => article.comments)
    @JoinColumn({ name: 'article_id' })
    article: Article

    @ManyToOne(() => User, user => user.articleCommentUser)
    author: User

    @ManyToOne(() => User, user => user.articleCommentReplayUser)
    replayUser: User
}